//存回nums1
public class array4 {
    public static void main(String[] args) {
        System.out.println("Hello Array");
        int[] nums1 = {1, 2, 3, 0, 0, 0};
        int[] nums2 = {2, 5, 6};
        int m = 3;
        int n = 3;
        System.out.println("m="+m);
        System.out.println("n="+n);
        merge(nums1, m, nums2, n);

        for (int i = 0; i < nums1.length; i++) {
            System.out.println("nums1["+i+"]="+nums1[i]);
        }
    }
    static void merge(int[] nums1, int m, int[] nums2, int n) {
        //int[] results = new int[m+n+1];
        // 2個陣列取小的
        int k = 0; 
        int i = 0, j = 0;
        while (i < m || j < n) {
            if (j >= n || ( i < m && nums1[i] <= nums2[j])) {
                nums1[k] = nums1[i];
                k ++;
                i++;
            } else{
                //results[k] = nums2[j];
                nums1[k] = nums2[j];
                k ++;
                j ++;
            }
    
        }

        //for (i = 0; i< m + n; i++)
        //    nums1[i] = results[i]; 
        

        
    }
}
